public class Solution6 {
    public String convert(String s, int numRows) {
        int len = s.length();
        char[] str = s.toCharArray();
        char[] res = new char[len];
        int index = 0;
        if (numRows == 1)
            return s;
        for (int i = 0; i < numRows; i++) {
            int j = i;
            int add = 1;
            boolean up = false;
            while (j < len) {
                if (add != 0) {
                    res[index] = str[j];
                    index++;
                }
                if (up) {
                    add = i * 2;
                    up = false;
                } else {
                    add = (numRows - i - 1) * 2;
                    up = true;
                }
                j += add;
            }
        }
        return String.valueOf(res);
    }
}
